/**
 * Created by gongxun on 17/1/14.
 */

var NnTableCardType = GameBaseItem.extend({
    Panel_niu : null,
    Panel_niuwu : null,
    Panel_effect : null,
    ctor : function(){
        this._super();
        this.loadCocostudio("res/ccs/NnTableCardType.json");
        this.Panel_niu = mo.seekWidgetByName(this.ccsNode, "Panel_niu");
        this.Panel_niuwu = mo.seekWidgetByName(this.ccsNode, "Panel_niuwu");
        this.Panel_effect = mo.seekWidgetByName(this.ccsNode, "Panel_effect");
    },

    showAnim : function(cardType){
        cc.log("cardType:" + cardType);
        if (cardType != -1){
            //显示
            this.setVisible(true);

            if (cardType == 0){
                this.showNiuWu();
            }else if (cardType < 10 || (cardType >= 101 && cardType <= 109)){
                this.showNiuNum(cardType);
            }else{
                this.showNiuBig(cardType);
            }
        }else{
            this.setVisible(false);
        }
    },

    showNiuWu : function(){
        this.Panel_niu.setVisible(false);
        this.Panel_niuwu.setVisible(true);
        this.Panel_effect.setVisible(false);

        var Sprite_wu = mo.seekWidgetByName(this.Panel_niuwu, "Sprite_wu");
        var Sprite_wu1 = mo.seekWidgetByName(this.Panel_niuwu, "Sprite_wu1");
        var Sprite_wu2 = mo.seekWidgetByName(this.Panel_niuwu, "Sprite_wu2");

        Sprite_wu.stopAllActions();
        Sprite_wu1.stopAllActions();
        Sprite_wu2.stopAllActions();

        Sprite_wu.setScale(1.4);
        Sprite_wu.setOpacity(100);
        Sprite_wu1.setVisible(false);
        Sprite_wu2.setVisible(false);

        Sprite_wu.runAction(cc.sequence(
            cc.spawn(
                cc.scaleTo(0.2, 1.0),
                cc.fadeIn(0.2)
            )
        ));

        Sprite_wu1.runAction(cc.sequence(
            cc.delayTime(0.4),
            cc.show()
        ));

        Sprite_wu2.runAction(cc.sequence(
            cc.delayTime(0.4),
            cc.show()
        ));
    },

    showNiuNum : function(cardType){
        this.Panel_niu.setVisible(true);
        this.Panel_niuwu.setVisible(false);
        this.Panel_effect.setVisible(true);
        this.showEffect(false);

        var Image_bg = mo.seekWidgetByName(this.Panel_niu, "Image_bg");
        var Image_niu = mo.seekWidgetByName(this.Panel_niu, "Image_niu");

        mo.gameHelper.loadTextureImage(Image_bg, "res/ccs/nn/anim/niu_bg_green.png");
        mo.gameHelper.loadTextureImage(Image_niu, "res/ccs/nn/anim/niu" + cardType + ".png");
    },

    showNiuBig : function(cardType){
        this.Panel_niu.setVisible(true);
        this.Panel_niuwu.setVisible(false);
        this.Panel_effect.setVisible(true);
        this.showEffect(true);

        var Image_bg = mo.seekWidgetByName(this.Panel_niu, "Image_bg");
        var Image_niu = mo.seekWidgetByName(this.Panel_niu, "Image_niu");

        mo.gameHelper.loadTextureImage(Image_bg, "res/ccs/nn/anim/niu_bg_reg.png");
        mo.gameHelper.loadTextureImage(Image_niu, "res/ccs/nn/anim/niu" + cardType + ".png");
    },

    showEffect : function(isBig){
        //特效
        var Image_ring = mo.seekWidgetByName(this.Panel_effect, "Image_ring");
        // var Particle_anim = mo.seekWidgetByName(this.Panel_effect, isBig ? "Particle_animBig" : "Particle_animSmall");

        // Particle_anim.stopAllActions();

        Image_ring.stopAllActions();
        Image_ring.setScale(0.5);
        Image_ring.setOpacity(255);
        Image_ring.setVisible(false);

        // if (cc.sys.isNative){
        //     Particle_anim.runAction(cc.sequence(
        //         cc.delayTime(0.3),
        //         cc.callFunc(function(){
        //             Particle_anim.start();
        //         })
        //     ));
        // }

        Image_ring.runAction(
            cc.sequence(
                cc.delayTime(0.1),
                cc.show(),
                cc.spawn(
                    cc.scaleTo(0.3, 1.5),
                    cc.fadeOut(0.3)
                )
            )
        );

        //缩放
        var Image_bg = mo.seekWidgetByName(this.Panel_niu, "Image_bg");
        var Image_niu = mo.seekWidgetByName(this.Panel_niu, "Image_niu");

        Image_bg.stopAllActions();
        Image_niu.stopAllActions();

        Image_bg.setScale(1.5);
        Image_niu.setScale(1.5);

        Image_bg.setOpacity(100);
        Image_niu.setOpacity(100);

        Image_bg.runAction(cc.sequence(
            cc.spawn(
                cc.scaleTo(0.2, 1.0),
                cc.fadeIn(0.2)
            )
        ));
        Image_niu.runAction(cc.sequence(
            cc.spawn(
                cc.scaleTo(0.2, 1.0),
                cc.fadeIn(0.2)
            )
        ));
    }
});